﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;

namespace myTunes.Test
{
    /// <summary>
    /// Summary description for iTunesPlayer_Test
    /// </summary>
    [TestClass]
    public class iTunesPlayer_Test
    {
        public iTunesPlayer_Test()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        //[TestMethod]
        public void PlaylistTest()
        {
            iTunesPlayer player = new iTunesPlayer();
            AutoResetEvent autoResetEvent = new AutoResetEvent(false);
            player.PropertyChanged += (sender, e) =>
                {
                    switch (e.PropertyName)
                    {
                        case "Playlists":
                            Assert.IsTrue(player.Playlists.Count > 0);
                            break;
                    }
                    autoResetEvent.Set();
                };
            
            autoResetEvent.WaitOne();
        }

        //[TestMethod]
        public void PlayPause()
        {
            iTunesPlayer player = new iTunesPlayer();
            AutoResetEvent autoResetEvent = new AutoResetEvent(false);
            player.PropertyChanged += (sender, e) =>
            {
                switch (e.PropertyName)
                {
                    case "Playlists":
                        {
                            player.Playlists[14].CurrentTrack.PlayPauseCommand.Execute(null);
                            /*
                            player.Playlists[13].TracksViewModel[1].PlayPauseCommand.Execute(player.Playlists[14].TracksViewModel[1]);
                            player.Playlists[14].TracksViewModel[2].PlayPauseCommand.Execute(null);
                            player.Playlists[14].TracksViewModel[2].PlayPauseCommand.Execute(null);
                            player.Playlists[14].TracksViewModel[2].PlayPauseCommand.Execute(null);
                            player.Playlists[14].TracksViewModel[2].PlayPauseCommand.Execute(null);
                            player.Playlists[14].TracksViewModel[2].PlayPauseCommand.Execute(null);*/
                        }
                        break;
                }
                autoResetEvent.Set();
            };

            autoResetEvent.WaitOne();
        }

        //[TestMethod]
        public void NextTrack()
        {
            iTunesPlayer player = new iTunesPlayer();
            AutoResetEvent autoResetEvent = new AutoResetEvent(false);
            player.PropertyChanged += (sender, e) =>
            {
                switch (e.PropertyName)
                {
                    case "Playlists":
                        {
                            //player.Playlists[13].TracksViewModel[1].PlayPauseCommand.Execute(player.Playlists[14].TracksViewModel[1]);
                            player.Playlists[14].TracksViewModel[0].PlayPauseCommand.Execute(null);
                            player.Playlists[14].NextTrackCommand.Execute(null);
                            player.Playlists[14].NextTrackCommand.Execute(null);
                            player.Playlists[14].PreviousTrackCommand.Execute(null);
                            player.Playlists[14].PreviousTrackCommand.Execute(null);
                        }
                        break;
                }
                autoResetEvent.Set();
            };

            autoResetEvent.WaitOne();
        }
    }
}
